﻿using Core.ECS;
using OpenTK.Windowing.GraphicsLibraryFramework;
using OpenTK.Mathematics;

namespace Core.ECS.Systems
{
    public static class Input
    {
        private static Vector2 lastMousePressedPosition;
        private static Vector2 lastMouseReleasedPosition;
        private static Vector2 lastMouseDownPosition;
        public static bool GetKeyDown(Keys key)
        {
            return Scene.Window.KeyboardState.IsKeyDown(key);
        }
        public static bool GetKeyPressed(Keys key)
        {
            return Scene.Window.KeyboardState.IsKeyPressed(key);
        }
        public static bool GetKeyReleased(Keys key)
        {
            return Scene.Window.KeyboardState.IsKeyReleased(key);
        }
        public static bool GetMouseButtonDown(MouseButton button)
        {
            bool isDown = Scene.Window.MouseState.IsButtonDown(button);
            if (isDown)
            {
                lastMouseDownPosition = new Vector2(Scene.Window.MouseState.X, Scene.Window.MouseState.Y);
            }
            return isDown;
        }
        public static bool GetMouseButtonPressed(MouseButton button)
        {
            bool isPressed = Scene.Window.MouseState.IsButtonPressed(button);
            if (isPressed)
            {
                lastMousePressedPosition = new Vector2(Scene.Window.MouseState.X, Scene.Window.MouseState.Y);
            }
            return isPressed;
        }
        public static bool GetMouseButtonReleased(MouseButton button)
        {
            bool isReleased = Scene.Window.MouseState.IsButtonReleased(button);
            if (isReleased)
            {
                lastMouseReleasedPosition = new Vector2(Scene.Window.MouseState.X, Scene.Window.MouseState.Y);
            }
            return isReleased;
        }
        public static Vector2 GetLastMouseDownPosition()
        {
            return lastMouseDownPosition;
        }
        public static Vector2 GetLastMousepPressedPosition()
        {
            return lastMousePressedPosition;
        }
        public static Vector2 GetLastMousepReleasedPosition()
        {
            return lastMouseReleasedPosition;
        }
    }
}
